package cn.edu.tju.elm.repository;

import cn.edu.tju.elm.model.entity.VirtualWallet;
import cn.edu.tju.elm.model.entity.WalletTransaction;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface WalletTransactionRepository extends JpaRepository<WalletTransaction, Long> {

    List<WalletTransaction> findByFromWalletOrToWalletOrderByTransactionTimeDesc(VirtualWallet fromWallet, VirtualWallet toWallet);

    @Query("SELECT wt FROM WalletTransaction wt WHERE wt.fromWallet.id = :walletId OR wt.toWallet.id = :walletId ORDER BY wt.transactionTime DESC")
    List<WalletTransaction> findByWalletId(@Param("walletId") Long walletId);

    List<WalletTransaction> findByOrderId(Long orderId);
}